#ifndef __HFI_Q_H__
#define __HFI_Q_H__

/* Private includes ----------------------------------------------------------*/
#include "main.h"
/* Private define ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/

typedef struct
{
  /* data */
  uint8_t u_in_flag;
  float u_in;
  float i_alphas;
  float i_betas;
  float i_alphas_last;
  float i_betas_last;
  float i_alphas_last_last;
  float i_betas_last_last;
  float i_alphah;
  float i_betah;
  float i_alphah_last;
  float i_betah_last;
  float i_alphah_delta;
  float i_betah_delta;

  float i_ds;
  float i_qs;
  float i_ds_last;
  float i_qs_last;
  float i_ds_last_last;
  float i_qs_last_last;
  float i_df;
  float i_qf;
  float i_dh;
  float i_qh;
  /*电流包络*/
  float ia;
  float ib;
  int sign;

  float theta;
  float delta_theta;
  float P_part;
  float I_part;
  float kp;
  float ki;
  float sin_pll;
  float cos_pll;

  float Angle;
  float Angle_last;
  float Angle_delta;
  float Angle_Err;
  float P;
  float I;
  float Kp;
  float Ki;
  float Omega;

  float Ts;
  float integral_gain;
  /*NS Check*/
  uint16_t ns_check_cnt;
  uint8_t hfi_init_flag;
  uint8_t hfi_inj_cnt;
  float trg_iq;
  float trg_id;
  float sum1;
  float sum2;

} HFI;

/* Private extern variables --------------------------------------------------*/
extern HFI hfi;
extern float target_id;
extern float target_iq;
/* Private function declaration ----------------------------------------------*/
void HFI_Init(HFI *hfi);
void HFI_AlphaBetah_Get(HFI *hfi, float i_alpha, float i_beta);
float HFI_Injc_Volt(HFI *hfi, float ud_in);
void HFI_dqf_Get(HFI *hfi, float i_ds, float i_qs);
void HFI_Pos_err(HFI *hfi);
void PLL_Cale_HFI(HFI *hfi);
void NS_Check(HFI *hfi);
#endif
